<?php
    require_once "class.poll.php";
    session_start();
    $_SESSION["id"] = session_id();
    function getPollData($_POST) {
        $data["title"] = $_POST["poll_title"];
        $data["count"] = $_POST["poll_customcount"]!=""?$_POST["poll_customcount"]:$_POST["poll_count"];
        $data["content"] = $_POST["poll_answer"];
        $data["cid"] = $_POST["poll_cid"];
        $data["multiple"] = $_POST["poll_multiple"];
        $data["shape"] = $_POST["poll_shape"];
        $data["dimension"] = $_POST["poll_dimension"];
        return $data;
    }
    if(isset($_REQUEST["act"])) {
        $poll = new poll();
        switch($_REQUEST["act"]) {
            case "addPoll":
                var_dump(getPollData($_POST));
//                $poll->createPoll($title,$count,$contents,$multiple,$shape,$dimension);
                break;
            case "getPoll":
                $poll->viewPoll($_POST["pid"]);
                break;
            case "editPoll":
                $poll->newPoll($_REQUEST["pid"]);
                break;
            case "updatePoll":
                echo "<pre>";
                $newData = getPollData($_POST);
                echo "</pre>";
                $poll->updatePoll($_REQUEST["pid"],$newData);
                break;
            case "contentDetail":
                $poll->display_ContentDetail($_REQUEST["pid"]);  //pid作为参数传递
                break;
            case "voteContent":
                $poll->voteContent($_REQUEST["pid"],$_REQUEST["cid"]);
                break;
            case "deletePoll":
                $poll->deletePoll($_REQUEST["pid"]);
                break;
            case "newPoll":
                $poll->newPoll();
                break;
            default:
                $poll = new poll();
                break;
        }
    } else {
        $poll = new poll();
?>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<script src="js.js" type="text/javascript"></script>
<?php
//        $poll->polllist();
//        $poll->viewPoll(0);
          $poll->latestPoll($_GET["manage"]);
    }
?>